import { host } from '@/config/env.config';
import { promisic } from './promisic';

class $http {
  static async request({ url, method = 'GET', data }) {
    const { globalData } = getApp();
    if (url.indexOf('http') !== 0) url = host + url;
    const res = await promisic(wx.request) ({
      url,
      method,
      data,
      header: {
        'my-token': encodeURIComponent(globalData.token)
      }
    })
    console.log(url + ' ==> ', res);
    return res.data;
  }
  static async get(url, data) {
    return this.request({
      url,
      method: 'get',
      data
    })
  }
  static async post(url, data) {
    return this.request({
      url,
      method: 'post',
      data
    })
  }
}

export { $http }